#include <bits/stdc++.h>
using namespace std;
#define FILENAME "detect"
const int N=1e5+5;
const int M=1e6+5;

bool __stb;

bool AA,BB,CC;
int n,m,L,V;
int d,v,a;
vector<pair<int,int> > t1,t2;
int p[N],b[M],s[M];

bool __enb;

void solve1() {
    AA=BB=CC=1;
    t1.clear();
    t2.clear();
    memset(b,0,sizeof(b));
    scanf("%d%d%d%d",&n,&m,&L,&V);
    for(int i=1;i<=n;i++) {
        scanf("%d%d%d",&d,&v,&a);
        if(a==0) {
            BB=CC=0;
            if(v>V) t1.emplace_back(make_pair(d,L));
        } else {
            int xx=(V*V-v*v)/(2*a);
            if(a>0) {
                AA=CC=0;
                if(v>V) {
                    t1.emplace_back(make_pair(d,L));
                    continue;
                }
				xx++;
                // if((V*V-v*v)%(2*a)!=0) xx++;
                int st=xx+d;
                if(st>L) continue;
                t1.emplace_back(make_pair(st,L));
            } else {
                AA=BB=0;
                if(V>v) continue;
                if((V*V-v*v)%(2*a)==0) xx--;
                if(d+xx<L) {
                    t1.emplace_back(make_pair(d,d+xx));
                } else {
                    CC=0;
                    t1.emplace_back(make_pair(d,L));
                }
            }
        }
    }
    for(int i=1;i<=m;i++) {
        scanf("%d",&p[i]);
        b[p[i]]=1;
    }
    for(int i=1;i<=L;i++) s[i]=s[i-1]+b[i];
    int ans1=0;
    for(pair<int,int> tp:t1) {
        int st=tp.first;
        int en=tp.second;
        if(s[en]-s[st-1]>0) {
            ans1++;
            t2.emplace_back(tp);
        }
    }
    printf("%d ",ans1);
}

namespace pts20 {
void solve2() {
    if(AA) {
        if(t2.size()==0) printf("%d\n",m);
        else printf("%d\n",m-1);
    }
}
}

namespace pts100 {
bool cmp(pair<int,int> p1,pair<int,int> p2) {
	if(p1.second==p2.second) return p1.first<p2.first;
	return p1.second<p2.second;
}
void solve2() {
	sort(t2.begin(),t2.end(),cmp);
	p[m+1]=1e9;
	int ans2=0,lst=0;
	for(int i=0;i<t2.size();i++) {
		if(p[lst]<t2[i].first) {
			while(p[lst]<=t2[i].second) lst++;
			lst--;
			ans2++;
		}
	}
	printf("%d\n",m-ans2);
}
}

int main() {
    fprintf(stderr,"%.2lf MB\n",(&__stb-&__enb)/1024.0/1024.0);
    freopen(FILENAME ".in","r",stdin);
    freopen(FILENAME ".out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--) {
		solve1();
		pts100::solve2();
	}
    return 0;
}

//by Ke9_qux
